#include "ftpsession.h"

FtpSession::FtpSession(qintptr socketHandle, const ServerConfig& serverConfig, QObject *parent) :
    QObject(parent),
    m_pi(new FtpServerPI(socketHandle, serverConfig)),
    m_dtp(new FtpServerDTP)
{
    m_pi->moveToThread(&m_piThread);
    m_dtp->moveToThread(&m_dtpThread);

    connect(&m_piThread, SIGNAL(started()), m_pi, SLOT(init()));
    connect(&m_piThread, SIGNAL(finished()), m_pi, SLOT(clean()));

    m_piThread.start();
    m_dtpThread.start();
}

FtpSession::~FtpSession()
{
    m_piThread.quit();
    m_dtpThread.quit();
    m_piThread.wait();
    m_dtpThread.wait();

    delete m_pi;
    delete m_dtp;
}
